package cn.bdqn.sp.controller;

import cn.bdqn.sp.pojo.SysUser;
import cn.bdqn.sp.utils.Constants;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SysInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        SysUser sysUser = (SysUser) session.getAttribute(Constants.SESSION_USER);

        if (sysUser == null){
            // 非法登录
            response.sendRedirect("/401.jsp");
            // 不继续 终止
            return false;
        }else {
            return true;
        }
    }
}
